<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 零度  <2109877665@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2019年08月20日
// +----------------------------------------------------------------------

/**
 * 订单列表
**/
$title='公告管理';
include './Head.php';
$my=isset($_GET['my'])?$_GET['my']:$_POST['my'];

?>
<style>
    .form-horizontal .form-group{
        margin: 0;
    }
</style>
<div class="row">
		<div class="col-sm-10 col-md-10">
			<div class="panel">
				<div class="panel-heading">
					<h4 class="panel-title">平台基本设置</h4>
				</div>
				<div class="panel-body">
    				<form id="form" method="post" class="form-horizontal" role="form">
    				        <div class="form-group">
                                <label>状态</label>
                                <select class="form-control" id="notice_state">
                                    <option value="on" <?php echo $conf['notice_state']=='on'?'selected':'';?>>开启</option>
                                    <option value="off"  <?php echo $conf['notice_state']=='off'?'selected':'';?>>关闭</option>
                                </select>
                            </div>
    						<div class="form-group">
                                <label>公告内容</label>
                                <textarea  id="notice" name="notice" class="form-control" rows="15"><?=$conf['notice']?></textarea>
                            </div>
                            <div class="form-group">
                                <label>上次更新时间</label>
                                <span class="form-control"><?=$conf['notice_update_time']?></span>
                            </div>
                            
    						<div class="form-group" style="margin-top:20px">
								<div class="col-sm-8"><input type="submit" name="submit" value="保存设置" class="btn btn-primary form-control"/></div>
							</div>
                    </form>
			    </div>
		    </div>
		</div>
</div>
<script src="//cdn.staticfile.org/layer/2.3/layer.js"></script>
 <script type="text/javascript">
 function dateFormat(fmt, date) {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}
 $(function(){
     $("#form").submit(function(e){
          e.preventDefault();
         var ii = layer.load(3, {shade:[0.1,'#fff']});
         var data ={
             notice: $("#notice").val(),
             notice_state:$("#notice_state").val()
         };
         data.notice_update_time = dateFormat('YYYY-mm-dd HH:MM:SS',new Date());
	  	$.ajax({
			type : "POST",
			url : "Ajax.php?act=saveNotice",
			data ,
			dataType : 'json',
			timeout:10000,
			success : function(data) {					  
				  layer.close(ii);
				  if(data.code==1){
					layer.alert('设置保存成功！', {
						icon: 1,
						closeBtn: false
					}, function(){
						window.location.reload()
					});
				  }
			},
			error:function(data){
				layer.close(ii);
				layer.msg('服务器错误');
			}
		});
     });
 })
  </script>